import { HintBtnView } from "../mapUI/HintBtnView";
import { IToolTipItem } from "../../../../com/mui/manager/IToolTipItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { LayerManager } from "../../manager/LayerManager";
import { RightTopLayerLine } from "../../manager/RightTopLayerLine";
import { RightTopLayerIndex } from "../../manager/RightTopLayerIndex";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { RemainTimeTool } from "./RemainTimeTool";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { GameController } from "../../mvc/GameController";
import { GameUI } from "../mainUI/GameUI";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { FlyToNavbarTool } from "./FlyToNavbarTool";
import { ItemConfig } from "../../resource/ItemConfig";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { Language } from "../../../../extend/language/Language";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
type int = number;
//class DailyAwardPanel
    
    export  class DailyAwardPanel extends HintBtnView implements IToolTipItem
    {
        constructor()
        {
            super();
            this._colorArr = [65280, 16776960, 16711680];
            this._preAwardArr = [];
            this._tf = new GTextFormat(null, 12);
            layer = LayerManager.rightTopUILayer;
            this.line = RightTopLayerLine.lineTwo;
            this.index = RightTopLayerIndex.DailyAwardPanel;
            _layer.addPopUp(this);
            buttonMode = true;
            this.mouseChildren = false;
            this.init();
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        public setAwardInfo(arg1: Object): void
        {
            var loc1=0;
            var loc2=null;
            if (this._isGainClick) 
            {
                this._isGainClick = false;
                loc1 = 0;
                while (loc1 < this._preAwardArr.length) 
                {
                    loc2 = this.getAwardImgPath(this._preAwardArr[loc1].code);
                    LoaderManager.instance.load(loc2, this.onFlyImgLoadedHandler);
                    ++loc1;
                }
            }
            this._awardBox.gotoAndStop(1);
            this._data = arg1;
            this._preAwardArr = arg1.reward;
            this._time = Number(arg1.time);
            if (this._preAwardArr.length > 0) 
            {
                this._timeTxt.text = RemainTimeTool.getRemainTimeBySeconds(this._time);
                this.setTimeTxtColor();
                if (this._secTimer != null) 
                {
                    this._secTimer.repeatCount = this._time;
                }
                else 
                {
                    this._secTimer = new SecTimer(1, this._time);
                    this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
                    this._secTimer.addListener(TimerType.COMPLETE, this.onCompleteHandler);
                }
                this._secTimer.start();
            }
            else 
            {
                removeEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
                (GameController.gameui.view as GameUI).removeDailyAward();
            }
            return;
        }

        /* internal  */onFlyImgLoadedHandler(arg1: ImageInfo): void
        {
            var loc1=this.localToGlobal(new Object /* flash.geom.Point */(10, 5));
            FlyToNavbarTool.flyToBackPack(arg1.bitmapData, loc1);
            return;
        }

        /* internal  */getAwardImgPath(arg1: int): string
        {
            var loc1=ItemConfig.instance.getInfoByCode(this._preAwardArr[0].code).item.icon;
            return loc1 + ".jpg";
        }

        /* internal  */init(): void
        {
            this._awardBox = GlobalClass.getInstance("DailyAward") as Object /* flash.display.MovieClip */;
            this._awardBox.gotoAndStop(1);
            this._awardBox.x = 0;
            this._awardBox.y = -20;
            this._awardBox.mouseEnabled = false;
            addChild(this._awardBox);
            this._timeTxt = new Object /* flash.text.TextField */();
            this._timeTxt.x = 3;
            this._timeTxt.y = this._awardBox.height;
            this._timeTxt.text = "00: 00: 00";
            this._timeTxt.width = 60;
            this._timeTxt.height = 20;
            this._timeTxt.mouseEnabled = false;
            this._timeTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            var loc1=new Object /* flash.filters.GlowFilter */(0, 0.5, 2, 2, 5);
            this._timeTxt.filters = [loc1];
            addChild(this._timeTxt);
            ToolTipsManager.register(this);
            return;
        }

        /* internal  */onTimerHandler(arg1: SecTimer): void
        {
            var loc1=0;
            this._timeTxt.text = RemainTimeTool.getRemainTimeBySeconds(arg1.repeatCount);
            var loc2;
            var loc3=((loc2 = this)._count + 1);
            loc2._count = loc3;
            if (this._count >= 5) 
            {
                this._count = 0;
                loc1 = Math.floor(Math.random() * 3);
                if (loc1 == this._idx) 
                {
                    loc1 = loc1 + 1;
                    if (loc1 >= this._colorArr.length) 
                    {
                        loc1 = 0;
                    }
                }
                this._idx = loc1;
                this._color = this._colorArr[loc1];
            }
            this.setTimeTxtColor();
            return;
        }

        /* internal  */setTimeTxtColor(): void
        {
            this._tf.color = this._color;
            this._timeTxt.setTextFormat(this._tf);
            return;
        }

        /* internal  */onCompleteHandler(arg1: SecTimer): void
        {
            arg1.stop();
            arg1.isDelete = false;
            this._timeTxt.text = Language.getString(90000);
            this.setTimeTxtColor();
            this._awardBox.play();
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._secTimer.repeatCount > 0) 
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(90015, this._timeTxt.text));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GainOnlineAward, this._data.type));
                this._isGainClick = true;
            }
            return;
        }

        /* internal  */playEnd(): void
        {
            this._awardBox.gotoAndPlay(2);
            return;
        }

        public /* override */ hide(): void
        {
            this._awardBox.stop();
            this.toolTipData = null;
            if (this._secTimer && this._secTimer.running) 
            {
                this._secTimer.stop();
            }
            super.hide();
            return;
        }

        public get toolTipData()
        {
            if (this._secTimer.repeatCount > 0) 
            {
                this._toolTipData = Language.getStringByParam(90016, this._timeTxt.text);
            }
            else 
            {
                this._toolTipData = Language.getString(90017);
            }
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._toolTipData = arg1;
            return;
        }

        /* internal */ /* var */_awardBox: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_timeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_data: Object;

        /* internal */ /* var */_time: number=0;

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_count: int=0;

        /* internal */ /* var */_color: uint=65280;

        /* internal */ /* var */_colorArr: Array<any>;

        /* internal */ /* var */_isGainClick: Boolean=false;

        /* internal */ /* var */_preAwardArr: Array<any>;

        /* internal */ /* var */_idx: int=-1;

        /* internal */ /* var */_tf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_toolTipData;
    }
